/*
 * @Author: 李琪 liqi@lark2game.com
 * @Date: 2025-08-08 17:03:31
 * @LastEditors: 李琪 liqi@lark2game.com
 * @LastEditTime: 2025-08-08 17:11:26
 * @FilePath: /gameWorld/assets/script/config/ConfigDataManager.ts
 * @Description: 章节配置数据管理
 */
import { Tables, temp } from "../template/schema";

export default class ConfigDataManager {
    public static instance: ConfigDataManager = new ConfigDataManager();
    private m_langMap: Map<number, temp.TempLanguage> | undefined;
    public dataTable: Tables = null!;
    /**
     * 0 中文简体
     * 1 中文繁体
     * 2 英文
    */
    private m_lang = '0';

    //初始化
    public init(table: any): void {
        // 设置配置数据
        this.dataTable = table;
        this.m_langMap = this.dataTable.Language.getDataMap();
    }
    getSubTable(key: string): any {
        const tables = this.dataTable[key as keyof typeof this.dataTable];
        return tables;
    }

    getSubTableList(key: string): any[] {
        const table = this.getSubTable(key);
        if (!table) {
            return null!;
        }
        return table.getDataList();
    }

    getSubTableMap(key: string): Map<number, any> {
        const table = this.getSubTable(key);
        if (!table) {
            return null!;
        }
        return table.getDataMap();
    }
    //#region 获取数据
    public getCurChapterData(chapter: number) {
        let ret: temp.TempChapter = null!;
        const tempChapter: temp.TempChapter[] = this.dataTable.Chapter.getDataList();
        tempChapter?.forEach((value, key) => {
            if (value.id == chapter) {
                ret = value;
            }
        });
        return ret;
    }
    // public getStageData(stage: number, chapterId: number): temp.TempStage | null {
    //     const key: string = 'Stage_' + chapterId;
    //     const configStageMap = this.getSubTableMap(key);
    //     return configStageMap.get(stage)!;
    // }
    // /**获取最后一关数据 */
    // public getLastStageData(chapterId: number): temp.TempStage | null {
    //     let ret: temp.TempStage | null = null;
    //     const key: string = 'StageBattle_' + chapterId;
    //     const configChapterInfoData: temp.TempStage[] = this.getSubTableList(key);
    //     const index = this.getCurChapterData(chapterId).stage;
    //     configChapterInfoData.forEach((value, key) => {
    //         if (value.id == index) {
    //             ret = value;
    //         }
    //     });
    //     return ret;
    // }
}
export const ConfigDataMgr = ConfigDataManager.instance;